// 引入接口函数
import {
    reqGetSearchGoodsInfoData
} from "@/api";

// 书写配置项
const state = {
    goodsInfo: {}
}
const actions = {
    // 获取搜索的商品信息
    async getSearchGoodsInfo({
        commit
    }, searchParams) {
        const result = await reqGetSearchGoodsInfoData(searchParams)
        if (result.code === 200) {
            commit('SAVE_SEARCH_GOODS_INFO', result.data)
        } else {
            console.log(result.message);
        }
    }
}
const mutations = {
    // 存储搜索到的商品数据
    SAVE_SEARCH_GOODS_INFO(state, goodsInfo) {
        state.goodsInfo = goodsInfo
    }
}
const getters = {
    // 商品列表数据
    goodsList(state) {
        return state.goodsInfo.goodsList;
    },
    // 详细属性列表
    attrsList(state) {
        return state.goodsInfo.attrsList;
    },
    // 品牌列表
    trademarkList(state) {
        return state.goodsInfo.trademarkList;
    },
    // 商品总数量
    total(state) {
        return state.goodsInfo.total
    }
}

// 导出模块
export default {
    namespaced: true,
    state,
    actions,
    mutations,
    getters
}